﻿using Ocelot.Configuration.File;
using Service.Framework.Utils.Helper;
using Service.Repository;
using SqlSugar;

namespace Service.Gateway.Domain.Db
{
    [SugarTable("tb_service_route")]
    public class ServiceRoute : Entity
    {
        public ServiceRoute()
        {
        }

        public ServiceRoute(long gatewayId, string downstreamPathTemplate, string upstreamPathTemplate,
            List<string> upstreamHttpMethod, FileRateLimitRule rateLimitOptions)
        {
            Id = SnowflakeUtil.Instance().GetId();
            GatewayId = gatewayId;
            DownstreamPathTemplate = downstreamPathTemplate;
            UpstreamPathTemplate = upstreamPathTemplate;
            UpstreamHttpMethod = upstreamHttpMethod;
            RateLimitOptions = rateLimitOptions;
        }

        /// <summary>
        /// 网关标识
        /// </summary>
        [SugarColumn(ColumnName = "id")]
        public long Id { get; private set; }

        /// <summary>
        /// 网关标识
        /// </summary>
        [SugarColumn(ColumnName = "gateway_id")]
        public long GatewayId { get; private set; }


        /// <summary>
        /// 下游地址
        /// </summary>
        [SugarColumn(ColumnName = "downstream_path_template")]
        public string DownstreamPathTemplate { get; private set; }

        /// <summary>
        /// 上游
        /// </summary>
        [SugarColumn(ColumnName = "upstream_path_template")]
        public string UpstreamPathTemplate { get; private set; }

        /// <summary>
        /// 请求方法
        /// </summary>
        [SugarColumn(ColumnName = "upstream_http_method", IsJson = true)]
        public List<string> UpstreamHttpMethod { get; private set; }


        /// <summary>
        /// 请求限制
        /// </summary>
        [SugarColumn(ColumnName = "rate_limit_options", IsJson = true)]
        public FileRateLimitRule RateLimitOptions { get; private set; }
    }
}